/*
 * Copyright 2007-2009 Thomas Krause (thomas@berlin-reloaded.de)
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.gidoo.cms.editor;

import org.gidoo.cms.GidooCMS;
import javax.swing.tree.TreeModel;
import javax.swing.tree.TreeNode;
import org.apache.wicket.ResourceReference;
import org.apache.wicket.markup.html.tree.BaseTree;
import org.apache.wicket.markup.html.tree.LinkIconPanel;
import org.apache.wicket.model.IModel;

/**
 *
 * @author <a href="mailto:thomas@berlin-reloaded.de">Thomas Krause</a>
 */
public class EditorTreePanel extends LinkIconPanel
{
  
  private TreeModel treeModel;
  
  /** Creates a new instance of EditorTreePanel */
  public EditorTreePanel(String id, IModel model, BaseTree tree)
  {
    super(id, model, tree);
    treeModel = (TreeModel) tree.getDefaultModelObject();
  }
  
  @Override
  protected ResourceReference getResourceFolderClosed(Object node)
  {
    return getRes((TreeNode) node);
  }

  @Override
  protected ResourceReference getResourceFolderOpen(Object node)
  {
    return getRes((TreeNode) node);
  }
  
  @Override
  protected ResourceReference getResourceItemLeaf(Object node)
  {
    return getRes((TreeNode) node);
  }
  
  private ResourceReference getRes(TreeNode node)
  {
    if(node.getParent() == treeModel.getRoot() || node.getParent() == null)
    {
      return new ResourceReference(GidooCMS.class, "res/singlesection.png");
    }
    else 
    {
      return new ResourceReference(GidooCMS.class, "res/page.png");
    }
  }

  
}
